COSC 220 Computer Science II

 

STL vector


This lab will give you some practical experience with vector APIs.

The function prints out all elements in a vector to cout.

template<typename T>
void writeVector(const vector<T>&vect);

 

The function performs a sequential search on a vector within range [first, last).

template<typenameT>
int seqVectSearch(const vector<T>&vect, int first, int last, const T&target);

 

The function removes all the duplicate entries from vect.

template<typenameT>
void removeDup(vector<T>&vect);  

Tasks (Important Do these tasks in the order given.)

  1. Copy vectorAux.cpp to your own directory. Just copy the file, don't write any code right now. vectorAux.cpp contains the following definitions:
    1. writeVector(const vector<T>& v) that writes vector v to cout.
    2. seqVectSearch(...) that performs a sequential search in a vector.
    3. removeDup(vector<T>& v) that removes duplicates from v using seqSearchVect.
  2. Copy vectorDriver.cpp to your own directory. Use this file as-is. No changes are needed.
  3. Based on the definitions and descriptions in vectorAux.cpp, write the appropriate header file vectorAux.h. This file must be guarded. Since template code is involved, #include "vectorAux.cpp" at the bottom of the header file. Be sure to document each function in the header file.
  4. Use g++ to compile and link vectorDriver.cpp. You should get no compilation or linking errors. If you do, fix the problem. Note that the output will not be correct if you run the program because some functions have not yet been implemented.
  5. Write seqSearchVect for vectors. Recompile vectorDriver.cpp to check for errors.
  6. Write removeDup. Compile, link, and run vectorDriver.cpp. Fix any errors. Your program should now be working for the removeDup function.

WHAT TO SUBMIT TO YOUR INSTRUCTOR: